package routes

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"web_app/controllers"
	"web_app/logger"
	"web_app/middleware"
	"web_app/pak/jwt"
	"web_app/tool"
)

func Setup() *gin.Engine {
	if !tool.IsDevelopment() { // 如果不是开发环境
		gin.SetMode(gin.ReleaseMode) // 设置成发布模式
	}

	r := gin.New()
	r.Use(logger.GinLogger(), logger.GinRecovery(true))

	r.POST("/signup", controllers.SignupHandler) // 注册
	r.POST("/login", controllers.LoginHandler)   // 登陆
	r.GET("/log", func(context *gin.Context) {
		jwt.LogoutToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjU5Mjc5NTg1MDYxMTUwNzMsInVzZXJfbmFtZSI6Imxpc2l4IiwiZXhwIjoxNjU4NTQyMzAyLCJpc3MiOiJibHVlYmVsbCJ9.i3KzP1am7_oAm9Ph0b1RZCLzZqROAy2u2OtVcGZ_PrQ")
	})
	r.Use(middleware.AuthorizationMiddleware()) // 增加用户认证中间件

	{
		r.GET("/user/info", controllers.UserInfoHandler)
		r.GET("/user/list", controllers.UserListHandler)
	}

	r.GET("/ping", func(c *gin.Context) {
		c.String(http.StatusOK, "212w12w")
	})

	return r
}
